package com.laboratory.asynctasklearning.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class LogService {

    @Async("asyncExecutor")
    public void saveLog(String msg) {
        System.out.println(Thread.currentThread().getName() + " 开始写日志: " + msg);
        try {
            Thread.sleep(2000); // 模拟耗时
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(Thread.currentThread().getName() + " 日志写入完成: " + msg);
    }

    public void saveLog(String msg, String name) {
        System.out.println(Thread.currentThread().getName() + " 开始写日志: " + msg + " " + name);
        try {
            Thread.sleep(2000); // 模拟耗时
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(Thread.currentThread().getName() + " 日志写入完成: " + msg + " " + name);
    }

}
